#ifndef __UPDATE_MBX_H__
#define __UPDATE_MBX_H__

/*
 *	mbx image head file
 */

struct entry_info {
	char name[15];
	unsigned char type;		// must be ENTRY_TYPE_*
	unsigned int offset;	// sub image offset in mbx image
	unsigned int length;	// sub image length in mbx image
	unsigned int __reserve[2];
} __attribute__((packed));

struct mbx_header {
	unsigned int magic;			// must be MBX_MAGIC
	unsigned int version;		// now version is 1.0
	unsigned int mbx_length;	// length of mbx image
	unsigned int verify;
	unsigned int __reserve[3];
	unsigned int entrys;
	struct entry_info entry_list[0];
} __attribute__((packed));

enum {
	MBX_ENTRY_TYPE_MBR,		// for MBR
	MBX_ENTRY_TYPE_UBOOT,	// for u-boot.imx
	MBX_ENTRY_TYPE_XLOGO,	// for loga.bmp
	MBX_ENTRY_TYPE_LBOOT,	// for linux boot.img
	MBX_ENTRY_TYPE_ABOOT,	// for android boot.img
	MBX_ENTRY_TYPE_RBOOT,	// for android recovery.img
	MBX_ENTRY_TYPE_LROOT,	// for linux rootfs
	MBX_ENTRY_TYPE_AROOT,	// for android system
	MBX_ENTRY_TYPE_LAPPS,	// for linux apps
	MBX_ENTRY_TYPE_ADATA,	// for android data
	MBX_ENTRY_TYPE_CACHE,	// for android cache
	MBX_ENTRY_TYPE_DEVIC,	// for android device
	MBX_ENTRY_TYPE_IDISK,	// for linux/android internal sdcard
	MBX_ENTRY_TYPE_MAX,
};

#define MBX_MAGIC				0x3158424D
#define MBX_VER_MAJOR(ver)		(ver >> 16)
#define MBX_VER_MINOR(ver)		(ver & 0xFFFF)

#define MBX_ENTRY_MAX			16

#define MBX_MAKE_VERSION(major, minor)	\
			((major & 0xFFFF) << 16 | (minor & 0xFFFF))


inline struct entry_info *mbx_get_entry(struct mbx_header *hdr, int type)
{
	if(!hdr || type >= MBX_ENTRY_TYPE_MAX)
		return NULL;

	for(unsigned int i = 0; i < hdr->entrys; ++i) {
		if(hdr->entry_list[i].type == type)
			return &hdr->entry_list[i];
	}
	return NULL;
}


#endif

